// pages/black/black.js
Page({
  data: {
    message:[
      
      //内容,头像，发帖人的名字，帖子id
      //我的id和帖子id

    ]
  },
  out:function(e){
    var that = this;
    var num =e.currentTarget.dataset.id;
    console.log(num);
    var black_post_id=that.data.message[num].black_post_id;
    var user_id=wx.getStorageSync('user_id');
    console.log(black_post_id);
    console.log(user_id);
    var obj={
      user_id:user_id,
      black_post_id:black_post_id
    }
    wx.request({
      url: 'https://api.yidan.work:2004/deleteBlack',
      header:{'content-type':'application/JSON'},
      method: 'POST',
      data:obj,
      success:(res)=>{
        wx.showToast({
          title: '移除成功',
          duration:1000
        })
        getCurrentPages()[getCurrentPages().length - 1].onLoad()
      },
      fail:(res)=>{
        console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    wx.request({
      url: `https://api.yidan.work:2004/black/${wx.getStorageSync('user_id')}`,
      header:{'content-type':'application/JSON'},
      method: 'GET',
      success:(res)=>{
        this.setData({
          message:res.data
        })
        console.log(this.data.message)
      },
      fail:(res)=>{
        console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: `https://api.yidan.work:2004/black/${wx.getStorageSync('user_id')}`,
      header:{'content-type':'application/JSON'},
      method: 'GET',
      success:(res)=>{
        this.setData({
          message:res.data
        })
        console.log(this.data.message)
      },
      fail:(res)=>{
        console.log(res.data)
      }
    })
  },

  onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading()
    //loading 提示框
    wx.showLoading({
      title: 'Loading...',
    })
    console.log("下拉刷新啦");
    setTimeout(function () {
      wx.hideLoading();
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh:function(){
    this.onRefresh();
  },
})